home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Range.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  58 lines

  1. #ifndef    RANGE_H
  2. #define    RANGE_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Range.h,v 3.0 90/05/20 00:20:57 kgorlen Rel $*/
  5.  
  6. /* Range.h -- header file for class Range
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     C. J. Eppich
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.  
  21. $Log:    Range.h,v $
  22.  * Revision 3.0  90/05/20  00:20:57  kgorlen
  23.  * Release for 1st edition.
  24.  * 
  25. */
  26.  
  27. #include "Object.h"
  28.  
  29. class Range: public VIRTUAL Object {
  30.     DECLARE_MEMBERS(Range);
  31.     int first,len;
  32. protected:        // storer() functions for object I/O
  33.     virtual void storer(OIOofd&) const;
  34.     virtual void storer(OIOout&) const;
  35. public:
  36.     Range()            { first = 0; len = -1; }
  37.     Range(int f, int l)    { first = f; len = l; }
  38.     int length() const    { return len; }
  39.     int length(int l)    { return len = l; }
  40.     int firstIndex() const    { return first; }
  41.     int firstIndex(int f)    { return first = f; }
  42.     int lastIndex() const    { return (first + len - 1); }
  43.     int lastIndex(int i)    { len = i - first + 1;  return i; }
  44.     bool valid() const    { return (len >= 0); }
  45.     void operator=(const Range& r)  { first = r.first;  len = r.len; }
  46.     bool operator==(const Range& r) const { return ((first == r.first) && (len == r.len)); }
  47.     bool operator!=(const Range& r)    const { return !(*this==r); }
  48.     virtual void deepenShallowCopy();    // {}
  49.     virtual unsigned hash() const;
  50.     virtual bool isEqual(const Object&) const;
  51.     virtual void printOn(ostream& strm =cout) const;
  52.     virtual const Class* species() const;
  53. private:                // shouldNotImplement()
  54.     virtual int compare(const Object&) const;
  55. };
  56.  
  57. #endif
  58.